/**
 * Copyright &copy; 2013-2016 山东易科德软件有限公司   All rights reserved.
 */
package cn.net.ecode.mdm.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.net.ecode.common.config.Global;
import cn.net.ecode.common.persistence.Page;
import cn.net.ecode.common.web.BaseController;
import cn.net.ecode.mdm.entity.MdmBtypeInfo;
import cn.net.ecode.mdm.service.MdmBtypeInfoService;

/**
 * 企业Controller
 * @author xiaodunshan
 * @version 2019-08-26
 */
@Controller
@RequestMapping(value = "${adminPath}/mdm/mdmBtypeInfo")
public class MdmBtypeInfoController extends BaseController {

	@Autowired
	private MdmBtypeInfoService mdmBtypeInfoService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public MdmBtypeInfo get(String id, boolean isNewRecord) {
		return mdmBtypeInfoService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("mdm:mdmBtypeInfo:view")
	@RequestMapping(value = {"list", ""})
	public String list(MdmBtypeInfo mdmBtypeInfo, Model model) {
		model.addAttribute("mdmBtypeInfo", mdmBtypeInfo);
		return "ecode/mdm/mdmBtypeInfoList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("mdm:mdmBtypeInfo:view")
	@ResponseBody
	@RequestMapping(value = "listData")
	public Page<MdmBtypeInfo> listData(MdmBtypeInfo mdmBtypeInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<MdmBtypeInfo> page = mdmBtypeInfoService.findPage(new Page<MdmBtypeInfo>(request, response), mdmBtypeInfo); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("mdm:mdmBtypeInfo:view")
	@RequestMapping(value = "form")
	public String form(MdmBtypeInfo mdmBtypeInfo, Model model) {
		model.addAttribute("mdmBtypeInfo", mdmBtypeInfo);
		return "ecode/mdm/mdmBtypeInfoForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("mdm:mdmBtypeInfo:edit")
	@ResponseBody
	@RequestMapping(value = "save")
	public String save(MdmBtypeInfo mdmBtypeInfo) {
		StringBuilder message = new StringBuilder();
		if (!beanValidator(message, mdmBtypeInfo)){
			return renderResult(Global.FALSE, message);
		}
		mdmBtypeInfoService.save(mdmBtypeInfo);
		return renderResult(Global.TRUE, "保存企业成功！");
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("mdm:mdmBtypeInfo:edit")
	@ResponseBody
	@RequestMapping(value = "delete")
	public String delete(MdmBtypeInfo mdmBtypeInfo) {
		mdmBtypeInfoService.delete(mdmBtypeInfo);
		return renderResult(Global.TRUE, "删除企业成功！");
	}


	@RequestMapping(value = "select")
	public String select(MdmBtypeInfo mdmBtypeInfo, Model model) {
		model.addAttribute("mdmBtypeInfo", mdmBtypeInfo);
		return "ecode/mdm/btypeSelect";
	}

}